layui.use('form', function() {
	var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
	//但是，如果你的HTML是动态生成的，自动渲染就会失效
	//因此你需要在相应的地方，执行下述方法来进行渲染
	form.render();
});
layui.use('laydate', function() {
	var laydate = layui.laydate;
	//执行一个laydate实例
	laydate.render({
		elem: '.base_create_date', //指定元素
		max: Date(),
	});

});

$(function() {
	$(".file_examine").change(function() {
		var imgfFile = $(".file_examine").prop("files")[0];
		console.log(imgfFile)
		$(".file_examine_span").html(imgfFile.name)
		//方法会读取指定的 Blob 或 File 对象。读取操作完成的时候，readyState 会变成已完成DONE，
		//并触发 loadend 事件，同时 result 属性将包含一个data:URL格式的字符串（base64编码）以表示所读取文件的内容。
	})

	$(".file_business").change(function() {
		var imgfFile = $(".file_business").prop("files")[0];
		console.log(imgfFile)
		$(".file_business_span").html(imgfFile.name)
		//方法会读取指定的 Blob 或 File 对象。读取操作完成的时候，readyState 会变成已完成DONE，
		//并触发 loadend 事件，同时 result 属性将包含一个data:URL格式的字符串（base64编码）以表示所读取文件的内容。
	})
})
/* 审批文件 */
function file_examine_button() {
	$(".file_examine").click();
}
/* 营业执照 */
function file_business_button() {
	$(".file_business").click();
}
function form_submit(){
	if(pd()){
		$("#base_form").submit();
	}
}

/* 验证 */
function pd(){
	var base_name = $(".base_name").val();
	var base_level = $(".base_level").val();
	var base_class = $(".base_class").val();
	var base_create_date = $(".base_create_date").val();
	var reference_number = $(".reference_number").val();
	var file_examine = $(".file_examine").val();
	var file_business = $(".file_business").val();
	var representative = $(".representative").val();
	var representative_phone = $(".representative_phone").val();
	var base_principal = $(".base_principal").val();
	var base_principal_phone = $(".base_principal_phone").val();
	var base_reservation = $(".base_reservation").val();
	var base_reservation_phone = $(".base_reservation_phone").val();
	var base_reservation_email = $(".base_reservation_email").val();
	var base_fixed_linetelephone = $(".base_fixed_linetelephone").val();
	var base_communication_address = $(".base_communication_address").val();
	var base_postal = $(".base_postal").val();
	
	var mobileReg_phone = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$|^0\d{2,3}-?\d{7,8}$/; //既验证手机号也验证固定电话
	var mobileReg_email = /^\w+@\w+(\.[A-Za-z]{2,3}){1,2}$/;//邮箱的正则表达式
	var mobileReg_postal=/^[0-9]\d{5}(?!\d)$/;//邮政编码
 	if(base_name.length <=0 || null == base_name){
		layer.msg('请输入基地名称',{icon:2});
		$(".base_name").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_name").css("border","0.5px solid #CCCCCC");
	}
	if(base_level.length <=0 || null == base_level){
		layer.msg('请输入所属级别',{icon:2});
		$(".base_level").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_level").css("border","0.5px solid #CCCCCC");
	}
	if(base_class.length <=0 || null == base_class){
		layer.msg('请输入使用学段',{icon:2});
		$(".base_class").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_class").css("border","0.5px solid #CCCCCC");
	}
	if(base_create_date.length <=0 || null == base_create_date){
		layer.msg('请输入建设时间',{icon:2});
		$(".base_create_date").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_create_date").css("border","0.5px solid #CCCCCC");
	}
	if(reference_number.length <=0 || null == reference_number){
		layer.msg('请输入审批文号',{icon:2});
		$(".reference_number").css("border","0.5px solid red");
		return false;
	}else{
		$(".reference_number").css("border","0.5px solid #CCCCCC");
	}
	if(file_examine.length <=0 || null == file_examine){
		layer.msg('请选择要上传的审批文件',{icon:2});
		return false;
	}
	if(file_business.length <=0 || null == file_business){
		layer.msg('请选择要上传的营业执照',{icon:2});
		return false;
	}	
 	if(representative.length <=0 || null == representative){
		layer.msg('请输入法定代表人',{icon:2});
		$(".representative").css("border","0.5px solid red");
		return false;
	}else{
		$(".representative").css("border","0.5px solid #CCCCCC");
	}
	
	if(representative_phone.length <=0 || null == representative_phone){
		layer.msg('请输入法定代表人联系方式',{icon:2});
		$(".representative_phone").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_phone.test(representative_phone)==false){
		layer.msg('法定代表人联系方式输入格式有误',{icon:2});
		$(".representative_phone").css("border","0.5px solid red");
		return false;
	}
	else{
		$(".representative_phone").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_principal.length <=0 || null == base_principal){
		layer.msg('请输入基地负责人',{icon:2});
		$(".base_principal").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_principal").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_principal_phone.length <=0 || null == base_principal_phone){
		layer.msg('请输入基地负责人人联系方式',{icon:2});
		$(".base_principal_phone").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_phone.test(base_principal_phone)==false){
		layer.msg('法定基地负责人联系方式输入格式有误',{icon:2});
		$(".base_principal_phone").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_principal_phone").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_reservation.length <=0 || null == base_reservation){
		layer.msg('请输入预订联系人',{icon:2});
		$(".base_reservation").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_reservation").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_reservation_phone.length <=0 || null == base_reservation_phone){
		layer.msg('请输入预订人联系方式',{icon:2});
		$(".base_reservation_phone").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_phone.test(base_reservation_phone)==false){
		layer.msg('法定基地预订人联系方式输入格式有误',{icon:2});
		$(".base_reservation_phone").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_reservation_phone").css("border","0.5px solid #CCCCCC");
	} 
	
 	if(base_reservation_email.length <=0 || null == base_reservation_email){
		layer.msg('请输入预订联系人邮箱',{icon:2});
		$(".base_reservation_email").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_email.test(base_reservation_email)==false){
		layer.msg('预订联系人邮箱输入格式有误',{icon:2});
		$(".base_reservation_email").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_reservation_email").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_fixed_linetelephone.length <=0 || null ==base_fixed_linetelephone){
		layer.msg('请输入固定电话',{icon:2});
		$(".base_fixed_linetelephone").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_phone.test(base_fixed_linetelephone)==false){
		layer.msg('固定电话输入格式有误',{icon:2});
		$(".base_fixed_linetelephone").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_fixed_linetelephone").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_communication_address.length <=0 || null == base_communication_address){
		layer.msg('请输入通信地址',{icon:2});
		$(".base_communication_address").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_communication_address").css("border","0.5px solid #CCCCCC");
	}
	
	if(base_postal.length <=0 || null == base_postal){
		layer.msg('请输入邮政编码',{icon:2});
		$(".base_postal").css("border","0.5px solid red");
		return false;
	}else if(mobileReg_postal.test(base_postal)==false){
		layer.msg('邮政编码输入格式有误',{icon:2});
		$(".base_postal").css("border","0.5px solid red");
		return false;
	}else{
		$(".base_postal").css("border","0.5px solid #CCCCCC");
		return true;
	}
}